package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author zcf
 */
@RestController
@RequestMapping("/admin/order")
@Api(tags = "管理端-订单接口")
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 取消订单
     */

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersRejectionDTO) {
        orderService.cancel(ordersRejectionDTO);
        return Result.success();
    }

    /**
     *订单搜索
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(int page, int pageSize, String number, String  beginTime, String endTime, Integer status,String phone) {
        PageResult pageResult = orderService.conditionSearch(page, pageSize, number, beginTime, endTime, status, phone);
        return Result.success(pageResult);
    }

    /**
     * 订单统计
     */
    @GetMapping("/statistics")
    @ApiOperation("订单统计")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO= orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 订单拒接
     */
    @PutMapping("/rejection")
    @ApiOperation("订单拒接")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 接单
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("订单完成")
    public Result complete(@PathVariable Long id) {
        orderService.complete(id);
        return Result.success();
    }

    /**
     * 查询订单详情
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> details(@PathVariable Long id) {
       OrderVO orderVO= orderService.getById(id);
        return Result.success(orderVO);
    }

    /**
     * 订单派送
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("订单派送")
    public Result delivery(@PathVariable Long id) {
        orderService.delivery(id);
        return Result.success();
    }
}
